package com.example.mongodb.mongodb.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

@Slf4j
@RestController
public class RedisController {

    private static JedisCluster jedisCluster;

    /**
     * 初始化redis cluster
     */
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        Set<HostAndPort> nodeList = new HashSet<>();
        nodeList.add(new HostAndPort("47.99.154.243", 6380));
        nodeList.add(new HostAndPort("47.99.154.243", 6381));
        nodeList.add(new HostAndPort("47.99.154.243", 6382));
        nodeList.add(new HostAndPort("123.207.179.78", 6383));
        nodeList.add(new HostAndPort("123.207.179.78", 6384));
        nodeList.add(new HostAndPort("123.207.179.78", 6385));
        jedisCluster = new JedisCluster(nodeList, 3000, config);

    }

    @GetMapping("/redisInit")
    public void redisInit() {
        jedisCluster.set("xiebing", "Bond");
        String value = jedisCluster.get("xiebing");
        System.out.println(value);


    }
}
